import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import com.eg.bm.common.dto.RequestDto;
import com.eg.bm.common.dto.ResponseDto;
import com.eg.bm.common.component.utils.ResponseUtil;

/**
* @author :${author}
* @description: ${desc} controller
* @create date: ${createDate}
*/


@RestController
@RequestMapping(value = "${entityNameLower}")
@Api(value="${entityName}controller",tags={"${desc} 信息接口"})
public class ${entityName}Controller {

    @Autowired
    ${entityName}Service ${entityNameLower}Service;

    @ApiOperation(value = "添加${desc}信息",httpMethod = "POST" )
    @PostMapping(value = "add")
    public ResponseDto<Integer> add(@RequestBody @Validated(${entityName}Dto.Add.class) RequestDto<${entityName}Dto> requestDto ){
        return ${entityNameLower}Service.add(requestDto.getData()) > 0?
        ResponseUtil.success():ResponseUtil.fail();
    }

    @ApiOperation(value = "修改${desc}信息",httpMethod = "POST" )
    @PostMapping(value = "update")
    public ResponseDto<Integer> update(@RequestBody @Validated(${entityName}Dto.Update.class) RequestDto <${entityName}Dto> requestDto ){
        return ${entityNameLower}Service.update(requestDto.getData()) > 0?
                ResponseUtil.success():ResponseUtil.fail();
     }

    <#if primaryKey!='noPrimaryKey'>
    @ApiOperation(value = "删除${desc}信息",httpMethod = "POST" )
    @PostMapping(value = "del")
    public ResponseDto <Integer> del(@RequestBody @Validated(${entityName}Dto.Delete.class) RequestDto<${entityName}Dto> requestDto ){
        return ${entityNameLower}Service.delete(requestDto.getData().${primaryKeyGet})> 0?
                        ResponseUtil.success():ResponseUtil.fail();
    }

    @ApiOperation(value = "查询${desc}信息详情",httpMethod = "POST" )
    @RequestMapping(value = "get",method = RequestMethod.POST)
    public ResponseDto<${entityName}Vo> get(@RequestBody RequestDto<${entityName}Dto> requestDto ){
        return ResponseUtil.success(${entityNameLower}Service.get(requestDto.getData().${primaryKeyGet}));
    }
    </#if>

    @ApiOperation(value = "查询${desc}信息列表",httpMethod = "POST" )
    @RequestMapping(value = "list",method = RequestMethod.POST )
    public ResponseDto<List<${entityName}Vo>> findList(@RequestBody RequestDto<${entityName}Dto> requestDto ){
        return ResponseUtil.successList(${entityNameLower}Service.findList(requestDto.getData()));
    }

    @ApiOperation(value = "查询${desc}分页列表信息",httpMethod = "POST" )
    @RequestMapping(value = "pagelist",method = RequestMethod.POST )
    public ResponseDto findPageList(@RequestBody RequestDto<${entityName}Dto> requestDto ){
        ${entityName}Dto ${entityNameLower}Dto = requestDto.getData();
        Integer pageNum = ${entityNameLower}Dto.getPageNum();
        Integer pageSize = ${entityNameLower}Dto.getPageSize();
        pageNum=pageNum==null?0:pageNum;
        pageSize=pageSize==null?10:pageSize;
        ${entityNameLower}Dto.setPageNum(pageNum);
        ${entityNameLower}Dto.setPageSize(pageSize);
        PageHelper.startPage(pageNum, pageSize);
        PageHelper.orderBy("update_time DESC");
        PageVO pageVO= ${entityNameLower}Service.findPageList(${entityNameLower}Dto);
        return ResponseUtil.success(pageVO);
    }
}